<?php

	/**
	 * 后台订单管理控制控制器
	 */
	 class OrderListController extends AuthController{
	 	
		private $model;
		
		public function __init(){
			parent::__init();
			$this->model = K('GoodsOrder');
		}
		
		/**
		 * 显示整个订单列表
		 */
		public function index(){
			//将所有的订单查询出来按时间倒序排序
			$status = Q('get.status','所有订单','strval');
			//按相应订单状态查询订单
			$data = $this->model->getStatusOrder($status);
			$this->assign('orderlists',$data['orderlists']);
			$this->assign('page',$data['page']);
			$this->display();
		}
		
		/**
		 * 显示订单明细
		 */
		 public function details(){
		 	$oid = Q('get.oid',0,'intval');
			$orderlist = current($this->model->where("oid={$oid}")->all());
			//查询相应的用户信息
			$username =K('Users')->where("uid={$orderlist['users_uid']}")->getField('username');
			//查询当前订单的商品明细
			$goodsLists = M()->join('__order_list__ ol JOIN __goods__ g ON ol.goods_gid=g.gid')->where("ol.order_oid={$orderlist['oid']}")->all();
//			p($goodsLists);
			$this->assign('goodslists',$goodsLists);
			$this->assign('username',$username);
			$this->assign('orderlist',$orderlist);
			$this->display();
		 }
		
		/**
		 * ajax修改订单状态
		 */
		 public function ajaxEditStatus(){
		 	if(!IS_AJAX) $this->error('非法请求');
			if($this->model->update(Q('post.'))){
				$this->ajax(array('message'=>'订单状态修改成功','status'=>1));
			}else{
				$this->ajax(array('message'=>'订单状态修改失败','status'=>0));
			}
		 }
		
		
	 }
	